﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.Util;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using LM.YF.K3Cloud.Plugin.Models;
using NumberHelper.Decimal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace LM.YF.K3Cloud.Plugin
{
    /// <summary>
    /// 货运单插件
    /// </summary>
    /// <remarks>
    /// 功能：1、运输路线变动时获取价格;2、获取默认路线2、获取运费价格&分摊重量价格
    /// 创建人：lxl
    /// 创建日期：2023-12-27
    /// 修改信息（1）：修改人，修改日期，修改内容
    /// </remarks>
    [HotUpdate, Description("货运单表单插件")]
    public class DiliveOrderBillPlugin : AbstractBillPlugIn
    {
        #region MyRegion

        /// <summary>
        /// 结算组织
        /// </summary>
        private readonly ElementKeySchema F_RDLV_SettlOrgId = new ElementKeySchema
        {
            FormKey = "F_RDLV_SettlOrgId",
            DbKey = "F_RDLV_SETTLORGID",
            OrmKey = "F_RDLV_SettlOrgId"
        };

        private readonly ElementKeySchema FEntity = new ElementKeySchema
        {
            FormKey = "FEntity",
            DbKey = "RDLV_t_DiliveOrdEntry",
            OrmKey = "FEntity"
        };

        /// <summary>
        /// 明细-发货组织
        /// </summary>
        private readonly ElementKeySchema F_RDLV_StockOrg2 = new ElementKeySchema
        {
            FormKey = "F_RDLV_StockOrg2",
            DbKey = "F_RDLV_StockOrg2",
            OrmKey = "F_RDLV_StockOrg2"
        };

        /// <summary>
        /// 运输计划点
        /// </summary>
        private readonly ElementKeySchema F_RDLV_StartCode = new ElementKeySchema
        {
            FormKey = "F_RDLV_StartCode",
            DbKey = "F_RDLV_STARTCODE",
            OrmKey = "F_RDLV_StartCode"
        };

        /// <summary>
        /// 单据头-价格表
        /// </summary>
        readonly ElementKeySchema F_RDLV_ShipPriceId = new ElementKeySchema
        {
            FormKey = "F_RDLV_ShipPriceId",
            DbKey = "F_RDLV_SHIPPRICEID",
            OrmKey = "F_RDLV_ShipPriceId"
        };

        /// <summary>
        /// 单据头-总运费
        /// </summary>
        readonly ElementKeySchema F_RDLV_ShipAmt = new ElementKeySchema
        {
            FormKey = "F_RDLV_ShipAmt",
            DbKey = "F_RDLV_SHIPAMT",
            OrmKey = "F_RDLV_ShipAmt"
        };

        /// <summary>
        /// 明细-重量占比
        /// </summary>
        readonly ElementKeySchema F_RDLV_WeightRate = new ElementKeySchema
        {
            FormKey = "F_RDLV_WeightRate",
            DbKey = "F_RDLV_WEIGHTRATE",
            OrmKey = "F_RDLV_WeightRate"
        };

        /// <summary>
        /// 明细-数量占比
        /// </summary>
        readonly ElementKeySchema F_RDLV_QtyRate = new ElementKeySchema
        {
            FormKey = "F_RDLV_QtyRate",
            DbKey = "F_RDLV_QTYRATE",
            OrmKey = "F_RDLV_QtyRate"
        };

        /// <summary>
        /// 明细-总重量
        /// </summary>
        readonly ElementKeySchema F_RDLV_RowWeigh = new ElementKeySchema
        {
            FormKey = "F_RDLV_RowWeigh",
            DbKey = "F_RDLV_ROWWEIGH",
            OrmKey = "F_RDLV_RowWeigh"
        };

        /// <summary>
        /// 明细-总运费
        /// </summary>
        readonly ElementKeySchema F_RDLV_RowAmt = new ElementKeySchema
        {
            FormKey = "F_RDLV_RowAmt",
            DbKey = "F_RDLV_ROWAMT",
            OrmKey = "F_RDLV_RowAmt"
        };

        #endregion

        private const ushort precision = 2;

        /// <summary>
        /// 字段变化
        /// </summary>
        /// <param name="e"></param>
        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            var priceType = Model.GetValue("F_RDLV_PriceType")?.ToString();
            switch (e.Field.Key.ToUpper())
            {
                case "F_RDLV_TRANSFERRUTE":// 运输路线
                    GetShipAmt();
                    break;
                case "F_RDLV_STARTCODE":// 运输计划点
                    GetShipAmt();
                    break;
                case "F_RDLV_WEIGHTRATE":// 重量占比变化
                    if (priceType == "1")
                    {
                        GetShipAmt();
                    }
                    break;
                case "F_RDLV_TOTALWEIGH":// 总重量
                    if (priceType == "1")
                    {
                        GetShipAmt();
                    }
                    break;
                case "F_RDLV_SHIPQTYTOTAL":// 计价数量总数
                    GetShipAmt();
                    break;
                case "F_RDLV_SHIPAMT":// 总运费
                    SplitShipFee();
                    break;
                default: break;
                case "F_RDLV_STOCKORG2":
                    SetFilter();
                    break;
            }
        }

        /// <summary>
        /// 当运费总价变化时，分摊运费到明细 
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        private void SplitShipFee()
        {
            //// 当没有计价表时，将运费总金额分摊到明细
            //DynamicObject shipPriceId = this.Model.GetValue(F_RDLV_ShipPriceId.OrmKey) as DynamicObject;
            //if (shipPriceId != null)
            //{
            //    return;
            //}

            // 总运费金额
            var totalAmount = Convert.ToDecimal(Model.GetValue(F_RDLV_ShipAmt.OrmKey));

            // 遍历单据体，分摊运费
            // 获取单据体实体
            Entity FEntity = View.Model.BusinessInfo.GetEntity("FEntity");
            // 获取单据体数据
            DynamicObjectCollection entityDataObject = View.Model.GetEntityDataObject(FEntity);

            // 如果存在没重量的分录，则使用数量占比
            bool useQty = entityDataObject
                .Any(i => Convert.ToSingle(i[F_RDLV_RowWeigh.OrmKey]) == 0);
            // 运费累加金额
            var subSumAmount = 0M;

            var lastRowIndex = entityDataObject.Count - 1;
            for (int i = 0; i <= lastRowIndex; i++)
            {
                // 前面行按照占比计算，最后一行到挤出数据
                if (i < lastRowIndex && totalAmount > 0)
                {
                    // 计算重量占比并赋值（如果存在没重量的分录，则使用数量占比）
                    decimal weightRate = useQty
                        ? Convert.ToDecimal(entityDataObject[i][F_RDLV_QtyRate.OrmKey])
                        : Convert.ToDecimal(entityDataObject[i][F_RDLV_WeightRate.OrmKey]);

                    // 计算每行分摊的运费
                    decimal rowAmt = (totalAmount * weightRate).Floor(precision);
                    //entityDataObject[i][F_RDLV_RowAmt.OrmKey] = rowAmt;
                    Model.SetValue(F_RDLV_RowAmt.FormKey, rowAmt, i);

                    // 前几行一共多少运费
                    subSumAmount += rowAmt;
                }
                else
                {   // 最后一行到挤出数据
                    var amt = totalAmount - subSumAmount;
                    //entityDataObject[i]["F_RDLV_RowAmt"] = amt;
                    Model.SetValue("F_RDLV_RowAmt", amt, i);
                }
            }
            View.UpdateView("FEntity");
        }

        /// <summary>
        /// 获取运费金额
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        private void GetShipAmt()
        {
            // 获取运输路线
            DynamicObject F_RDLV_TransferRute = Model.GetValue("F_RDLV_TransferRute") as DynamicObject;
            // 获取运费计价方式
            string F_RDLV_PriceTypeId = Convert.ToString(Model.GetValue("F_RDLV_PriceType"));
            // 获取单据体实体
            Entity FEntity = View.Model.BusinessInfo.GetEntity("FEntity");
            // 获取单据体数据
            DynamicObjectCollection entityDataObject = View.Model.GetEntityDataObject(FEntity);
            // 没有运输路线，清空,返回
            if (F_RDLV_TransferRute == null)
            {
                // 赋值总运费
                Model.SetValue("F_RDLV_ShipAmt", 0);
                // 没有运输路线，默认就是重量计价
                Model.SetValue("F_RDLV_ShipUnit", 0);
                // 清空运费计价数量
                Model.SetValue("F_RDLV_ShipQtyTotal", 0);
                // 清空单据体运输单价
                for (int i = 0; i < entityDataObject.Count; i++)
                {
                    Model.SetValue("F_RDLV_RowAmt", 0, i);
                }
                return;
            }
            //当选择了运输路线,并且是重量计价时，获取路线价
            if (F_RDLV_PriceTypeId == "1")
            {
                GetWeighAmt(entityDataObject);
            }
            //当选择了运输路线，但不是重量计价时
            else
            {
                GetOtherShipAmt(entityDataObject);
            }
        }

        /// <summary>
        /// 获取体积、集装箱、车次计价方法
        /// </summary>
        private void GetOtherShipAmt(DynamicObjectCollection entityDataObject)
        {
            //赋值总运费
            this.Model.SetValue("F_RDLV_ShipAmt", 0);
            //清空单据体运输单价
            for (int i = 0; i < entityDataObject.Count; i++)
            {
                this.Model.SetValue("F_RDLV_RowAmt", 0, i);
            }

            //组单日期
            string date = this.Model.GetValue("F_RDLV_Date")?.ToString();
            //运输路线
            DynamicObject F_RDLV_TransferRute = this.Model.GetValue("F_RDLV_TransferRute") as DynamicObject;
            string F_RDLV_TransferRuteId = F_RDLV_TransferRute?["id"].ToString() ?? "0";
            //运输计划点
            DynamicObject F_RDLV_StartCode = this.Model.GetValue("F_RDLV_StartCode") as DynamicObject;
            string F_RDLV_StartCodeid = F_RDLV_StartCode?["id"].ToString() ?? "0";
            //获取运输量
            decimal F_RDLV_ShipQtyTotal = Convert.ToDecimal(this.Model.GetValue("F_RDLV_ShipQtyTotal"));
            //获取运输路线计价表
            string strSql = $@"select a.fid,b.F_RDLV_ClassType,F_RDLV_ClassQty
                , F_RDLV_Price, F_RDLV_Unit, F_RDLV_Currency
                from RDLV_t_ShipRutePrice a
                inner join RDLV_t_ShipRutePriceEntry b on a.fid=b.fid and a.FDOCUMENTSTATUS='C'and a.F_RDLV_ShipRute={F_RDLV_TransferRuteId}
                and '{date}' between F_RDLV_StartDate and F_RDLV_EndDate and F_RDLV_ShipCode={F_RDLV_StartCodeid} 
                and {F_RDLV_ShipQtyTotal}>0
                and ( ({F_RDLV_ShipQtyTotal}<=F_RDLV_ClassQty and F_RDLV_ClassType='小于等于')
                or({F_RDLV_ShipQtyTotal}<F_RDLV_ClassQty and F_RDLV_ClassType='小于' ))
                order by F_RDLV_ClassQty";
            //this.View.ShowMessage(strSql);
            DynamicObjectCollection getData = DBUtils.ExecuteDynamicObject(this.Context, strSql);
            if (getData != null && getData.Count > 0)
            {
                //获取第一行满足条件的数据，即为运费单价
                decimal fPrice = Convert.ToDecimal(getData[0]["F_RDLV_Price"]);
                //赋值运费的单价
                this.Model.SetValue("F_RDLV_PRICE", fPrice);
                //计算整单运价
                decimal F_RDLV_ShipAmt = fPrice * F_RDLV_ShipQtyTotal;
                //赋值总运费
                this.Model.SetValue("F_RDLV_ShipAmt", F_RDLV_ShipAmt);
                //赋值运费计价单位
                string F_RDLV_ShipUnit = Convert.ToString(getData[0]["F_RDLV_Unit"]);
                this.View.Model.SetValue("F_RDLV_ShipUnit", F_RDLV_ShipUnit);
                //赋值使用的价格表
                string fShipPriceId = Convert.ToString(getData[0]["fid"]);
                View.Model.SetValue("F_RDLV_ShipPriceId", fShipPriceId);

                // 如果存在没重量的分录，则使用数量占比
                bool useQty = entityDataObject.Any(i => Convert.ToSingle(i[F_RDLV_RowWeigh.OrmKey]) == 0);
                var subSumAmount = 0M;
                for (int i = 0; i < entityDataObject.Count; i++)
                {
                    //前面行按照占比计算，最后一行到挤出数据
                    if (i < entityDataObject.Count - 1 && F_RDLV_ShipQtyTotal > 0)
                    {
                        // 计算重量占比并赋值（如果存在没重量的分录，则使用数量占比）
                        decimal weightRate = useQty
                            ? Convert.ToDecimal(entityDataObject[i][F_RDLV_QtyRate.OrmKey])
                            : Convert.ToDecimal(entityDataObject[i][F_RDLV_WeightRate.OrmKey]);

                        //计算每行分摊的运费
                        decimal F_RDLV_RowAmt = (F_RDLV_ShipAmt * weightRate).Floor(precision);
                        //entityDataObject[i]["F_RDLV_RowAmt"] = F_RDLV_RowAmt;
                        Model.SetValue("F_RDLV_RowAmt", F_RDLV_RowAmt, i);
                        //扣减整单剩余金额
                        subSumAmount += F_RDLV_RowAmt;
                    }
                    else
                    {   //最后一行到挤出数据
                        var amt = F_RDLV_ShipAmt - subSumAmount;
                        // entityDataObject[i]["F_RDLV_RowAmt"] = amt;
                        Model.SetValue("F_RDLV_RowAmt", amt, i);
                    }
                }
                this.View.UpdateView("FEntity");
            }
            else//没有计价信息，清空
            {
                //赋值总运费
                this.Model.SetValue("F_RDLV_ShipAmt", 0);
                //清空运费单价
                this.Model.SetValue("F_RDLV_PRICE", 0);
                //清空已经使用的运费计价表
                this.View.Model.SetValue("F_RDLV_ShipPriceId", 0);
                //清空单据体运输费用
                for (int i = 0; i < entityDataObject.Count; i++)
                {
                    this.Model.SetValue("F_RDLV_RowAmt", 0, i);
                }
            }
        }

        /// <summary>
        /// 获取重量计价运费
        /// </summary>
        /// <param name="entityDataObject">单据体</param>
        /// <param name="F_RDLV_TransferRute">运输路线id</param>
        private void GetWeighAmt(DynamicObjectCollection entityDataObject)
        {
            // 运输路线
            DynamicObject F_RDLV_TransferRute = Model.GetValue("F_RDLV_TransferRute") as DynamicObject;
            string F_RDLV_TransferRuteId = F_RDLV_TransferRute?["id"].ToString() ?? "0";
            // 运输计划点
            DynamicObject F_RDLV_StartCode = Model.GetValue("F_RDLV_StartCode") as DynamicObject;
            string F_RDLV_StartCodeid = F_RDLV_StartCode?["id"].ToString() ?? "0";
            // 组单日期
            string date = Model.GetValue("F_RDLV_Date")?.ToString();
            // 获取总重量
            decimal F_RDLV_TotalWeigh = Convert.ToDecimal(Model.GetValue("F_RDLV_TotalWeigh"));

            // 获取当前路线的价格：时间、路线过滤，按照等级数量升序排列，获取第一条满足的数据
            // 暂时不考虑单位、币种
            string strSql = $@"select a.fid, b.F_RDLV_ClassType, F_RDLV_ClassQty
                    , F_RDLV_Price, F_RDLV_Unit,F_RDLV_Currency
                from RDLV_t_ShipRutePrice a
                inner join RDLV_t_ShipRutePriceEntry b on a.fid = b.fid and a.FDOCUMENTSTATUS = 'C'
                    and a.F_RDLV_ShipRute = {F_RDLV_TransferRuteId}
                    and '{date}' between F_RDLV_StartDate and F_RDLV_EndDate
                    and F_RDLV_ShipCode = {F_RDLV_StartCodeid}
                    and {F_RDLV_TotalWeigh} > 0
                    and (
                        ({F_RDLV_TotalWeigh} <= F_RDLV_ClassQty and F_RDLV_ClassType = '小于等于')
                        or ({F_RDLV_TotalWeigh} < F_RDLV_ClassQty and F_RDLV_ClassType = '小于')
                    )
                order by F_RDLV_ClassQty;";
            DynamicObjectCollection getData = DBUtils.ExecuteDynamicObject(Context, strSql);
            if (getData?.Count > 0)
            {
                // 获取第一行满足条件的数据，即为运费单价
                decimal fPrice = Convert.ToDecimal(getData[0]["F_RDLV_Price"]);
                // 赋值运费的单价
                Model.SetValue("F_RDLV_PRICE", fPrice);
                // 计算整单运价
                decimal F_RDLV_ShipAmt = fPrice * F_RDLV_TotalWeigh;
                // 赋值总运费
                Model.SetValue("F_RDLV_ShipAmt", F_RDLV_ShipAmt);
                // 赋值运费计价单位
                string F_RDLV_ShipUnit = Convert.ToString(getData[0]["F_RDLV_Unit"]);
                View.Model.SetValue("F_RDLV_ShipUnit", F_RDLV_ShipUnit);
                // 赋值使用的价格表
                string fShipPriceId = Convert.ToString(getData[0]["fid"]);
                View.Model.SetValue("F_RDLV_ShipPriceId", fShipPriceId);

                // 如果存在没重量的分录，则使用数量占比
                bool useQty = entityDataObject.Any(i => Convert.ToSingle(i[F_RDLV_RowWeigh.OrmKey]) == 0);
                var subSumAmount = 0M;
                for (int i = 0; i < entityDataObject.Count; i++)
                {
                    // 前面行按照占比计算，最后一行到挤出数据
                    if (i < entityDataObject.Count - 1 && F_RDLV_TotalWeigh > 0)
                    {
                        // 计算重量占比并赋值（如果存在没重量的分录，则使用数量占比）
                        decimal weightRate = useQty
                            ? Convert.ToDecimal(entityDataObject[i][F_RDLV_QtyRate.OrmKey])
                            : Convert.ToDecimal(entityDataObject[i][F_RDLV_WeightRate.OrmKey]);

                        // 计算每行分摊的运费
                        decimal F_RDLV_RowAmt = (F_RDLV_ShipAmt * weightRate).Floor(precision);
                        // entityDataObject[i]["F_RDLV_RowAmt"] = F_RDLV_RowAmt;
                        Model.SetValue("F_RDLV_RowAmt", F_RDLV_RowAmt, i);
                        // 扣减整单剩余金额
                        subSumAmount += F_RDLV_RowAmt;
                    }
                    else
                    {
                        // 最后一行到挤出数据
                        var amt = F_RDLV_ShipAmt - subSumAmount;
                        //entityDataObject[i]["F_RDLV_RowAmt"] = amt;
                        Model.SetValue("F_RDLV_RowAmt", amt, i);
                    }
                }
            }
            else
            {
                // 没有计价信息，清空
                // 赋值总运费
                Model.SetValue("F_RDLV_ShipAmt", 0);
                // 清空运费单价
                Model.SetValue("F_RDLV_PRICE", 0);
                // 清空已经使用的运费计价表
                View.Model.SetValue("F_RDLV_ShipPriceId", 0);
                // 清空单据体运输费用
                for (int i = 0; i < entityDataObject.Count; i++)
                {
                    Model.SetValue("F_RDLV_RowAmt", 0, i);
                }
            }
        }

        /// <summary>
        /// 获取运输路线
        /// </summary>
        private void GetTransRute()
        {
            // 货运运输区域 
            var F_RDLV_EndRegionId = Convert.ToInt32((View.Model.GetValue("F_RDLV_EndRegion") as DynamicObject)?["id"]);
            // 获取计重方式
            var F_RDLV_PriceTypeId = Convert.ToInt32(Model.GetValue("F_RDLV_PriceType"));
            // 获取起运点 
            var F_RDLV_start_pointId = Convert.ToInt32((View.Model.GetValue("F_RDLV_start_point") as DynamicObject)?["id"]);
            // 查询默认路线
            if (F_RDLV_EndRegionId != 0 && F_RDLV_PriceTypeId != 0 && F_RDLV_start_pointId != 0)
            {
                // F_RDLV_PlanCode={F_RDLV_StartCodeId}
                var strSql = $@"select fid
                    from RDLV_t_TransfRute
                    where 1 = 1
                        and F_RDLV_Destion = {F_RDLV_EndRegionId}
                        and F_RDLV_PriceType = {F_RDLV_PriceTypeId}
                        and FDOCUMENTSTATUS = 'C'
                        and F_RDLV_START_POINT = {F_RDLV_start_pointId}
                    order by F_RDLV_Default desc";
                DynamicObjectCollection getResultData = DBUtils.ExecuteDynamicObject(Context, strSql);
                if (getResultData != null && getResultData.Count > 0)
                {
                    var fruteId = Convert.ToString(getResultData[0]["fid"]);
                    View.Model.SetValue("F_RDLV_TransferRute", fruteId);
                }
                else
                {
                    View.Model.SetValue("F_RDLV_TransferRute", "0");
                }
            }
            else
            {
                View.Model.SetValue("F_RDLV_TransferRute", "0");
            }
        }

        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
        }

        public override void AfterDeleteRow(AfterDeleteRowEventArgs e)
        {
            SetFilter();
        }

        private void SetFilter(string formKey, string filter)
        {
            var element = View.BusinessInfo.GetElement(formKey);
            element.SetPropertyValue("Filter", filter);
            View.UpdateView(formKey);
        }

        /// <summary>
        /// 给结算组织添加过滤条件：只能从分录-发货组织中选择
        /// 给运输计划点添加过滤条件：计划点发货组织需要同时包含所有货运单分录发货组织
        /// </summary>
        private void SetFilter()
        {
            string settlOrgFilter = "", startCodeFilter = "";

            var entity = Model.BusinessInfo.GetEntryEntity(FEntity.FormKey);
            var entryDataCollection = Model.GetEntityDataObject(entity);
            var orgNumbers = new List<string>();
            foreach (var entryData in entryDataCollection)
            {
                // 遍历货运单分录，获取分录中的发货组织
                var orgData = entryData[F_RDLV_StockOrg2.OrmKey] as DynamicObject;
                var orgNumber = orgData?["Number"]?.ToString();
                if (string.IsNullOrWhiteSpace(orgNumber) || orgNumbers.Contains(orgNumber))
                {
                    continue;
                }
                orgNumbers.Add(orgNumber);
            }

            var orgNumbersCount = orgNumbers.Count;
            if (orgNumbersCount > 0)// 有分录则计算过滤条件
            {
                // 结算组织设置过滤条件
                var strOrgNumbers = string.Join("','", orgNumbers);
                settlOrgFilter = $"FNumber in ('{strOrgNumbers}')";

                // 计划点设置过滤条件
                // 原过滤条件：F_RDLV_OrgId='GetValue(F_RDLV_StockOrg)'
                //var startCodeNumberCollection = DBUtils.ExecuteDynamicObject(Context, $@"select a.FNUMBER
                //    from RDLV_t_PlanCode as a-- 运输计划点
                //    inner join RDLV_t_PlanCodeEntry as b on b.FID = a.FID-- 运输计划点分录
                //    inner join T_ORG_Organizations as c on c.FNUMBER in ('{strOrgNumbers}') and c.FORGID = b.F_RDLV_STOCKORG-- 查询发货组织为指定编号的运输计划点分录
                //    where a.FDOCUMENTSTATUS = 'C'
                //    group by a.FNUMBER
                //    having count(distinct b.F_RDLV_STOCKORG) = {orgNumbersCount};-- 组织编号属于指定组织，并且分录数量与组织数量相等，说明运输计划点的分录发货组织刚好等于指定的那几个组织");
                //var startCodeNumbers = startCodeNumberCollection.Select(i => i["FNUMBER"].ToString());
                //if (startCodeNumbers.Count() > 0)
                //{
                //    startCodeFilter = $"FNumber in ('{string.Join("','", startCodeNumbers)}')";
                //}
                //else
                //{
                //    // 没查到数据就不允许选择
                //    startCodeFilter = "FNumber = '-1'";
                //}
            }

            //SetFilter(F_RDLV_SettlOrgId.FormKey, settlOrgFilter);
            //SetFilter(F_RDLV_StartCode.FormKey, startCodeFilter);
        }

        public override void BeforeF7Select(BeforeF7SelectEventArgs e)
        {
            base.BeforeF7Select(e);
            if (e.FieldKey.ToUpper() == F_RDLV_StartCode.FormKey.ToUpper())
            {
                SetFilter();
            }
        }
    }
}
